import axios from "axios";
import { Message } from "element-ui";

// export const baseUrl =
//   process.env.NODE_ENV === "development"
//     ? "http://localhost:9999"
//     : config.baseUrl;
export const baseUrl = "http://120.26.130.99:9999";

axios.defaults.baseURL = baseUrl;
axios.defaults.withCredentials = true;

axios.interceptors.response.use(
  response => {
    // if (response.data.code === 100) {
    //   return Promise.reject(response.data)
    // }
    // else {
    //   Message.warning(response.data.msg)
    // }
    return response.data;
  },
  error => {
    if (error.response) {
      let status = error.response.status;
      if (status === 404) {
        Message.warning("接口未找到!");
      } else {
        Message.error("服务器繁忙,请稍后再试!");
      }
      return Promise.reject(error);
    }
    Message.error("未知错误!");
    return Promise.reject(error);
  }
);
